package com.ziytek.web.citizen.service;

import com.ziytek.web.citizen.configuration.db.DDS;
import com.ziytek.web.citizen.constant.DdsConstant;
import com.ziytek.web.citizen.mapper.OperationDetailEasyMapper;
import com.ziytek.web.citizen.mapper.UpdateBatchWrapper;
import com.ziytek.web.citizen.pojo.basic.OperationDetail;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 批量操作详情服务
 *
 * @author fenghx
 */

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OperationDetailEasyService {
    private final OperationDetailEasyMapper operationDetailEasyMapper;

    @DDS(DdsConstant.DS_BASIC)
    public void insertBatchSomeColumn(List<OperationDetail> entityList) {
        if (CollectionUtils.isEmpty(entityList)) {
            return;
        }

        try {
            operationDetailEasyMapper.insertBatchSomeColumn(entityList);
        } catch (Exception e) {
            log.error("OperationDetail insertBatchSomeColumn error:", e);
        }
    }

    @DDS(DdsConstant.DS_BASIC)
    public void updateBatchById(List<OperationDetail> entityList) {
        if (CollectionUtils.isEmpty(entityList)) {
            return;
        }
        try {
            operationDetailEasyMapper.updateBatchById(entityList,
                    new UpdateBatchWrapper<OperationDetail>().setUpdateFields(OperationDetail::getUpdateTime,
                            OperationDetail::getCabinetNo, OperationDetail::getBatterySerial, OperationDetail::getStepId,
                            OperationDetail::getStartFlag, OperationDetail::getOperationId, OperationDetail::getSingleType,
                            OperationDetail::getCellNum, OperationDetail::getOrderNo, OperationDetail::getBoardLineNum,
                            OperationDetail::getBoardAddress, OperationDetail::getFirstOrderTime, OperationDetail::getBeginTime,
                            OperationDetail::getEndTime, OperationDetail::getInterruptTimeSecond, OperationDetail::getInterruptCap,
                            OperationDetail::getBatchNo));
        } catch (Exception e) {
            log.error("OperationDetail updateBatchById error:", e);
        }
    }
}
